﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

/// <summary>
/// From：张帅
/// PS：自走棋选船Item
/// </summary> 
namespace UI
{
    public class ChessChooseShipItem : MonoBehaviour
    {
        public Material grayMaterial;
        public Text shipName;
        public TextureKit icon;
        public GameObject selected;
        int shipId;
        bool isGet, isSelect;
        System.Action<int> onClick;
        public void OnClick()
        {
            if(onClick != null && isGet && !isSelect)
            {
                onClick(shipId);
            }
        }

        public void SetItem(ShipData data, bool isSelect, System.Action<int> onClick)
        {
            this.isSelect = isSelect;
            this.onClick = onClick;
            shipId = data.shipId;
            var dict = Table.Blo.TableShipBlo.GetTableShip(data.shipId);
            icon.TextureName = dict.shipIcon;
            shipName.text = dict.shipName;
            selected.SetActiveEx(isSelect);
            isGet = data.IsGet();
            if (!isGet && !isSelect)
            {
                icon.image.material = grayMaterial;
            }
        }

        public void SetSelectState(bool isSelect)
        {
            this.isSelect = isSelect;
            selected.SetActiveEx(isSelect);
        }
    }
}
